package com.xteam.ecsystem.directive;

import static freemarker.template.ObjectWrapper.DEFAULT_WRAPPER;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xteam.ecsystem.base.Constant;
import com.xteam.ecsystem.entities.SysNavConfig;
import com.xteam.ecsystem.service.front.FrontSysCfgService;
import com.xteam.ecsystem.utils.DirectiveUtil;

import freemarker.core.Environment;
import freemarker.template.TemplateDirectiveBody;
import freemarker.template.TemplateDirectiveModel;
import freemarker.template.TemplateException;
import freemarker.template.TemplateModel;

/**
 * 系统导航标签(获取系统导航配置)
 * @author ls
 */
@Service
public class SysNavConfigDirective implements TemplateDirectiveModel {
	
	@Autowired
	private FrontSysCfgService fscService;

	@SuppressWarnings("unchecked")
	public void execute(Environment env, Map params, TemplateModel[] loopVars,
			TemplateDirectiveBody body) throws TemplateException, IOException {
		/*
		int sncpage = DirectiveUtil.getInteger(params, Constant.PAR_SNCPAGE.value());
		int sncposition = DirectiveUtil.getInteger(params, Constant.PAR_SNCPOSITION.value());
		int pageIndex = DirectiveUtil.getInteger(params, Constant.PAR_PAGEINDEX.value());
		int pageSize = DirectiveUtil.getInteger(params, Constant.PAR_PAGESIZE.value());
		PageCenterStation<SysNavConfig> pcs = this.fscService.getNavConfigs(sncpage,sncposition,pageIndex,pageSize);
		env.setVariable(Constant.VAR_SYSNAVCONFIG.value(),DEFAULT_WRAPPER.wrap(pcs));
		body.render(env.getOut());
		*/
		//int sncPage = DirectiveUtil.getInteger(params, Constant.PAR_SNCPAGE.value());
		int sncPosition = DirectiveUtil.getInteger(params, Constant.PAR_SNCPOSITION.value());
		
		List<SysNavConfig> list = this.fscService.getNavConfigList(sncPosition);
		env.setVariable(Constant.VAR_SYSNAVCONFIGLIST.value(),DEFAULT_WRAPPER.wrap(list));
		body.render(env.getOut());
	}
}